package com.shxy.common;

/**
 * 结果枚举
 */
public enum ResultCode {
    // 成功
    SUCCESS(200, "成功"),
    // 失败
    COMMON_FAIL(500, "失败"),

    // 参数错误
    PARAM_NOT_VALID(1001, "参数无效"),
    PARAM_IS_BLANK(1002, "参数为空"),
    PARAM_TYPE_ERROR(1003, "参数类型错误"),
    PARAM_NOT_COMPLETE(1004, "参数未填写完整"),

    // 用户错误
    USER_NOT_LOGIN(2001, "用户未登录"),
    USER_ACCOUNT_EXPIRED(2002, "账号已过期"),
    USER_CREDENTIALS_ERROR(2003, "账号或密码错误"),
    USER_CREDENTIALS_EXPIRED(2004, "密码过期"),
    USER_ACCOUNT_DISABLE(2005, "账号不可用"),
    USER_ACCOUNT_LOCKED(2006, "账号被锁定"),
    USER_ACCOUNT_NOT_EXIST(2007, "账号不存在"),
    USER_ACCOUNT_ALREADY_EXIST(2008, "账号已存在"),
    USER_ACCOUNT_USE_BY_OTHERS(2009, "账号下线"),
    USER_ACCOUNT_PASSWORD_ERROR(2010, "账号或密码有误"),

    USER_ROLE_IS_EXIST(2010, "用户角色已存在"),
    USER_ROLE_NOT_EXIST(2011, "用户角色不存在"),

    // 权限错误
    NO_PERMISSION(3001, "没有权限"),

    // 路径错误
    URL_ERROR(4001, "路径错误")
    ;

    private Integer code;
    private String message;

    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * 根据编码获取信息
     * @param code
     * @return
     */
    public String getMessageByCode(Integer code) {
        for(ResultCode rc: values()) {
            if(rc.getCode().equals(code)) {
                return rc.getMessage();
            }
        }
        return null;
    }
}
